<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/18
 * Time: 16:50
 */

namespace App\Imports;


use App\Rules\Mobile;
use App\Services\AlibabaServices;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\SkipsFailures;
use Maatwebsite\Excel\Concerns\SkipsOnFailure;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithValidation;

class MessageImport implements ToCollection, WithHeadingRow, WithValidation
{
    use Importable;


    public function collection(Collection $rows)
    {

        /*foreach ($rows as $row)
        {
            $validator  = Validator::make($row->toArray(), $this->rules());

            if($validator->fails()){
                $this->onFailure($validator->messages()->toArray());
//                dd($validator->messages());
            }else{
                Log::info($row['mobile']);
            }
        }*/
        return $this;
    }

    public function rules(): array
    {
        return [
            'mobile' => ['required',new Mobile],
        ];
    }
}
